import request from '@/api/request'
import { AxiosPromise } from 'axios'

enum API {
    BASE_URL = "/system/v1/users",
    PAGE_URL = "/system/v1/users/page",
    BATCH_DELETE_URL = "/system/v1/users/batch-delete",
    ASSIGN_ROLES_URL = "/system/v1/users/assign-roles"
}

export const assignRolesApi = (userId:string|number,roleIds:(string|number)[]):AxiosPromise<any> => {
    return request.put<any>(API.ASSIGN_ROLES_URL+"/"+userId,roleIds)
}

export const fetchRolesOfUserApi = (userId:string|number):AxiosPromise<any> => {
    return request.get<any>(API.BASE_URL+"/"+userId+"/roles")
}

export const fetchUsersPageApi = (current:number,size:number,data:any):AxiosPromise<any> => {
    return request.post<any>(API.PAGE_URL+"/"+current+"/"+size,data)
}

export const createUserApi = (query:any):AxiosPromise<any> => {
    return request.post<any>(API.BASE_URL,query)
}

export const updateUserApi = (query:any):AxiosPromise<any> => {
    return request.put<any>(API.BASE_URL,query)
}

export const deleteUserByIdApi = (id:string|number):AxiosPromise<any> => {
    return request.delete<any>(API.BASE_URL+'/'+id)
}

export const batchDeleteUsersApi = (ids:(string|number)[]):AxiosPromise<any> => {
    return request.put<any>(API.BATCH_DELETE_URL,ids)
}

export const batchUploadUserApi = ():AxiosPromise<any> => {
    return request.get<any>(API.BASE_URL+'/upload')
}

export const avatarUpload = (data:any):AxiosPromise<any> => {
    return request.post<any>(API.BASE_URL+'/avatar',data)
}


export const getAvatar = (filePath:string):AxiosPromise<any> => {
    return request.get<any>(API.BASE_URL+'/avatar',{params:{
        filePath
    },responseType:'blob'})
}

export const getLoginUserApi = ():AxiosPromise<any> => {
    return request.get<any>(API.BASE_URL+'/loginuser')
}